#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

static bool func(uint64_t n) {
    vector<uint64_t> v;
    for (uint64_t m = n; m; m /= 10) 
        v.push_back(m % 10);
    sort(v.begin(), v.end());

    for (uint64_t i = 2; i <= 6; ++i) {
        vector<uint64_t> p;
        for (uint64_t m = i * n; m; m /= 10)
            p.push_back(m % 10);
        sort(p.begin(), p.end());
        if (v != p)
            return false;
    }

    return true;
}

int main() {
    for (int i = 1; ; ++i) {
        if (func(i)) {
            cout << i << endl;
            break;
        }
    }
}